package metrics

import (
	"github.com/prometheus/client_golang/prometheus"
)

const (
	MetricsNamspace = "httpserver"
)

var (
	functionLatency     = CreateExecutionTimerMetric(MetricsNamspace, "Time spent.")
	funcTotolRequestInc = CreateTotalRequestsMetric(MetricsNamspace)
	fubcApiDuration     = CreateNewSortApiGauge(MetricsNamspace)
)

func Register() {
	//prometheus.Register(functionLatency)
	//registry := prometheus.NewRegistry()
	//// 可选: 添加 process 和 Go 运行时指标到我们自定义的注册表中
	//registry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
	//registry.MustRegister(collectors.NewGoCollector())
	// 全全局注册多个指标
	prometheus.MustRegister(functionLatency)
	prometheus.MustRegister(funcTotolRequestInc)
	prometheus.MustRegister(fubcApiDuration)

}

func NewTimer(url string) *ExecutionTimer {
	return NewExecutionTimer(functionLatency, url)
}

func NewRequestCounter(url string, amethod string) *RequestCounter {
	return NewTotalRequestCounter(funcTotolRequestInc, url, amethod)
}

func NewApiDuration(method string) *ApiDurationGauge {
	return NewApiDurationGauge(fubcApiDuration, method)
}
